// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/parking/api/ParkCarApplyApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/parking/model/ParkCarListQueryReq'
import PassClass from '@api/parking/model/ParkingApplyApproveReq'

const RejClass = PassClass

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

const USER = {
  auditBy: CORE.USER.uaaUserId,
  auditByName: CORE.USER.name,
}

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'queryApplyList', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },

  // —————————————————————————————— 通过 —————————————————————————————— //

  async pass({ id }, TIP = '通过') {
    const DTO = CORE.grpcDTO(PassClass, { applyId: id, status: 2, ...USER })
    await CORE.grpc(TIP, CLIENT, 'approve', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 拒绝 —————————————————————————————— //

  async rej({ id }, TIP = '拒绝') {
    const DTO = CORE.grpcDTO(RejClass, { applyId: id, status: 3, ...USER })
    await CORE.grpc(TIP, CLIENT, 'approve', DTO)
    return CORE.grpcOK(TIP)
  },
}
